package com.mdlib.helper.ui.fragments.sect.send;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.ljlib.help.R;
import com.mdlib.helper.base.BaseTitleFragment;
import com.mdlib.helper.ui.adapter.GenericViewPagerAdapter;
import com.mdlib.helper.ui.fragments.sect.vicinity.VicinityOrderFragment;
import com.mdlib.helper.ui.fragments.sect.vicinity.VicinityRunFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;


/**
 * 作者：HQY on 16/11/14 13:09
 * 邮箱：hqy_xz@126.com
 */

public class VicinityFragment extends BaseTitleFragment {


    @Bind(R.id.tab_vicnity_top)
    TabLayout mTabVicnityTop;

    @Bind(R.id.vp_FindFragment_pager)
    ViewPager mVpFindFragmentPager;

    private VicinityOrderFragment vicinityOrderFragment;

    private VicinityRunFragment vicinityRunFragment;

    private FragmentPagerAdapter vicinityAdapter;

    private List<Fragment> listFragment;

    private List<String> titlFragment;


    public static VicinityFragment newInstance() {
        return new VicinityFragment();
    }


    @Override
    protected void initView(View rootView) {
        super.initView(rootView);
        setTitle(R.string.vicinity_tv_title, R.color.white)
                .setTitleBgColor(R.color.generic_view_bg)
                .setImgLeftListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        removeFragment();
                    }
                });
        init();
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.fragment_vicnity;
    }

    private void init() {
        vicinityOrderFragment = new VicinityOrderFragment();
        vicinityRunFragment = new VicinityRunFragment();


        listFragment = new ArrayList<>();
        listFragment.add(vicinityOrderFragment);
        listFragment.add(vicinityRunFragment);

        titlFragment = new ArrayList<>();
        titlFragment.add(getActivity().getResources().getString(R.string.vicinity_tv_order_title));
        titlFragment.add(getActivity().getResources().getString(R.string.vicinity_tv_run_title));

        mTabVicnityTop.setTabMode(TabLayout.MODE_FIXED);

        mTabVicnityTop.addTab(mTabVicnityTop.newTab().setText(titlFragment.get(0)));
        mTabVicnityTop.addTab(mTabVicnityTop.newTab().setText(titlFragment.get(1)));

        vicinityAdapter = new GenericViewPagerAdapter(getActivity().getSupportFragmentManager(), listFragment, titlFragment);
        mVpFindFragmentPager.setAdapter(vicinityAdapter);
        mTabVicnityTop.setupWithViewPager(mVpFindFragmentPager);


    }
}
